package com.eusoft.grades.school;
/**
 * @author Nick Eubanks
 * 
 * Copyright (C) 2010 Android Infinity (http://www.androidinfinity.com)
 *
 */
import com.eusoft.grades.school.Course_Schedule_ContainerGroup;
import com.eusoft.grades.school.Course_Schedule_Container;

public class ProcessCourseID {

	public static String createIdFromContainerGroup(Course_Schedule_ContainerGroup G) {
		String s = G.name + "::" + G.location + "::" + G.startDate + "::"
				+ G.endDate + "::" + G.containers.size() + "::";

		for (Course_Schedule_Container c : G.containers) {
			s += c.EVENT_ID + "::" + c.sunday + "::" + c.monday + "::"
					+ c.tuesday + "::" + c.wednesday + "::" + c.thursday + "::"
					+ c.friday + "::" + c.saturday + "::" + c.startHour + "::"
					+ c.endHour + "::" + c.startMin + "::" + c.endMin + "::";
		}

		for (Course_Schedule_Container c : G.containers) {
			s += c.location + "::";
		}

		return s;
	}

	public static Course_Schedule_ContainerGroup interpretID(String id) {
		Course_Schedule_ContainerGroup G = new Course_Schedule_ContainerGroup();
		String[] s = id.split("::");

		G.name = s[0];
		G.location = s[1];
		G.startDate = new Long(s[2]);
		G.endDate = new Long(s[3]);

		int groups = new Integer(s[4]);
		int i = 5;
		for (; i < (groups * 12);) {
			Course_Schedule_Container c = new Course_Schedule_Container();
			c.EVENT_ID = new Integer(s[i++]);
			c.sunday = new Boolean(s[i++]);
			c.monday = new Boolean(s[i++]);
			c.tuesday = new Boolean(s[i++]);
			c.wednesday = new Boolean(s[i++]);
			c.thursday = new Boolean(s[i++]);
			c.friday = new Boolean(s[i++]);
			c.saturday = new Boolean(s[i++]);
			c.startHour = new Integer(s[i++]);
			c.endHour = new Integer(s[i++]);
			c.startMin = new Integer(s[i++]);
			c.endMin = new Integer(s[i++]);
			G.containers.add(c);
		}

		try {
			for (Course_Schedule_Container c : G.containers) {
				c.location = s[i++];
			}
		} catch (Exception e) {
			for (Course_Schedule_Container c : G.containers) {
				c.location = G.location;
			}
		}

		return G;
	}

}
